<template>
	<view>
		<!-- 商品列表 -->
		<view class="detail-desc">
		<!-- 	<view class="d-header">
				<text>商品列表</text>
			</view> -->
			<!-- <view v-for="(item,i) in data" :key="i" class="item" style="width: 95%;margin: 0 2.5%;margin-top: 20upx;">
				<image class="triangle" :src="item.goods_thumb" mode="widthFix" style="border-radius: 20upx;border: 1upx solid #DDDDDD;box-shadow: 1upx 1upx 10upx #DDDDDD;" @click="jumpgoods(item.id)"></image>
				<view class="detail">
					<view class="name" style="color: #000000;font-weight: 555;font-size: 30upx;height: 47upx;">{{item.goods_desc}}</view>
					<view class="webkit" style="position: relative;height: 30upx;">
						<text style="font-size: 24upx;color: #aaaaaa;font-weight: 550;" class="flex"> {{item.goods_name}} </text>
						<view style="position: absolute;top: -10upx;right: 20upx;">
							<text style="color: #aaaaaa;padding: 0 5upx;">|</text><text style="font-weight: 555;font-size: 34upx;">￥{{item.cost_price}}</text><text>/</text><text style="text-decoration: line-through;color: #aaaaaa;font-size: 22upx;">{{item.level_price}}</text>
						</view>
					</view>
				</view>
			</view> -->
			
			<view class="guess-section">
				<view 
					v-for="(item, index) in data" :key="index"
					class="guess-item"
					@click="jumpgoods(item.id)"
				>
					<view class="image-wrapper" @click="navToDetailPage(item.id)" style="border-radius: 0;">
						<image :src="item.goods_thumb" mode="aspectFill"></image>
					</view>
					<view style="height: 230upx;background-color: #fafafa;text-align: center;">
						<view style="height: 60upx;line-height: 90upx;font-size: 30upx;font-family:'STHeiti';">
							{{item.goods_name}}
						</view>
						<view style="height: 60upx;">
							￥{{item.cost_price}}
						</view>
						<view style="height: 60upx;line-height: 60upx;">
							<view style="display: inline-block;width: 200upx;height: 60upx;line-height: 60upx;border: 2upx solid #000000;text-align: center;">
								立即购买
							</view>
						</view>
					</view>
				</view>
			</view>
		</view>
		
		
		
	</view>
</template>

<script>
	export default {
		data() {
			return {
				data:[],
				user_id:'',
				res:[],
				page: 1,
			}
		},
		onLoad(){
			uni.getStorage({
				key: 'user_id',
				success: (res) => {
				  this.user_id = res.data
				},
			});
			this.loadData();
		},
		// onPullDownRefresh() {
		// 	let o = this
		// 	setTimeout(function () {
		// 		o.getmorenews();
				
				
		// 		uni.stopPullDownRefresh();
		// 	}, 1000);
		// },
		// 上拉加载
		onReachBottom(){
			if (this.timer != null) {
				clearTimeout(this.timer)
			}
			this.timer = setTimeout(()=> {
				this.getmorenews()
			}, 1000);
		},
		methods: {
			loadData(){
				// 商品列表
				let o = this
				uni.request({
				    url: 'https://cx.mingmeijt.com/Api/Goods/index',
						method: 'POST',
						data:{
							user_id: this.user_id,
							session_id: uni.getStorageSync("sessionid")
						},
						header:{'Content-Type':'form-data'},
				    success: (res) => {
							console.log(res)
							this.data = res.data.data.list
							for(var i=0; i<o.data.length; i++) {
								o.data[i].goods_detail = 'https://cx.mingmeijt.com' + o.data[i].goods_detail
							}
							for(var i=0; i<o.data.length; i++) {
								o.data[i].goods_thumb = 'https://cx.mingmeijt.com' + o.data[i].goods_thumb
							}
						}
				});
			},
			getmorenews() {
				this.page++;//每触底一次 page +1
				uni.request({
					url: 'https://cx.mingmeijt.com/Api/Goods/index?p=' + this.page,
					method: 'POST',
					data:{
						user_id: this.user_id,
						session_id: uni.getStorageSync("sessionid")
					},
					header:{'Content-Type':'application/x-www-form-urlencoded'},
					success: res => {
						if(res.data.code == 999){
							uni.navigateTo({
								url:'/pages/999/999'
							})
						};
						if(res.data.code == 998){
							uni.navigateTo({
								url:'/pages/login/login'
							})
						}
						// console.log(res.data.data.data.list)
						if (res.data.data.list == '' || res.data.data.list == null || res.data.data.list == []) { //没有数据
							uni.showToast({
								title: '我也是有底线的哦~~',
								icon: 'none'
							})
							return;
						}
						for(var i=0; i<res.data.data.list.length; i++) {
							res.data.data.list[i].goods_thumb = 'https://cx.mingmeijt.com' + res.data.data.list[i].goods_thumb
						}
						this.data = this.data.concat(res.data.data.list);//将数据拼接在一起
						console.log(this.data)
					},
					fail: () => {},
					complete: () => {}
				});
			},
			jumpgoods(orderid){
				uni.navigateTo({
					url: '/pages/product/product?goodsid=' + orderid
				})
			},
		}
	}
</script>

<style lang='scss'>
	.guess-section{
		display:flex;
		flex-wrap:wrap;
		/* padding: 0 30upx; */
		background: #fff;
		.guess-item{
			display:flex;
			flex-direction: column;
			width: 49%;
			padding-bottom: 40upx;
			&:nth-child(2n+1){
				margin-right: 2%;
			}
		}
		.image-wrapper{
			width: 100%;
			height: 330upx;
			border-radius: 3px;
			overflow: hidden;
			image{
				width: 100%;
				height: 100%;
				opacity: 1;
			}
		}
		.title{
			font-size: $font-lg - 4upx;
			color: #000000;
			line-height: 80upx;
		}
		.price{
			font-size: $font-lg - 4upx;
			color: #000000;
			line-height: 1;
		}
	}
	
	
	.detail-desc{
		background: #fff;
		/* margin-top: 16upx; */
		.d-header{
			display: flex;
			justify-content: center;
			align-items: center;
			height: 80upx;
			font-size: $font-base + 2upx;
			color: $font-color-dark;
			position: relative;
				
			text{
				padding: 0 20upx;
				background: #fff;
				position: relative;
				z-index: 1;
			}
			&:after{
				position: absolute;
				left: 50%;
				top: 50%;
				transform: translateX(-50%);
				width: 300upx;
				height: 0;
				content: '';
				border-bottom: 1px solid #ccc;
			}
		}
	}
	
	.triangle {
		width: 100%;
		height: 350upx;
		/* height: 666upx; */
		display: block;
	}
	.detail {
		background: #fff;
		padding: 20upx 12upx;
	}
	.name {
		height: 68upx;
		overflow: hidden;
		text-overflow: ellipsis;
		display: -webkit-box;
		-webkit-line-clamp: 2;
		-webkit-box-orient: vertical;
		font-size: 24upx;
		line-height: 36upx;
	}
	.item {
		width: 100%;
		padding: 10upx;
		box-sizing: border-box;
	}
</style>
